#pragma once

/*
#include "IController.h"
#include "Collection.h"

#include  "..\Streaming\USCInterfaces.h"
#include  "..\Streaming\USCSingletone.h"
*/

#include <string>

using namespace std;

#ifndef ISERIALIZABLE
#define ISERIALIZABLE

  namespace Serialization
  {
    /*
    namespace Descriptions
    {
      enum CreationStates
      {
        ISCS_Unknown,
        ISCS_Opened,
        ISCS_Created,
      };
      struct Descriptor
      {
        CreationStates CreationState; 
        Descriptor():CreationState(ISCS_Unknown) { }
      };
    }

    class IFile
    {
    public:
      virtual bool Write( void* pbuffer, UINT offset, UINT size )=0;
      virtual bool Read ( void* pbuffer, UINT offset, UINT size )=0;
      virtual UINT64 GetSize()=0;
      virtual Descriptions::Descriptor GetDescriptor()const=0;
    };
    */
    class IStream
    {
    public:
      enum Direction
      {
        ISD_Unknown,
        ISD_Forward,
        ISD_Backward,
      };
    public:
      virtual bool Write( void* pbuffer, UINT size )=0;
      virtual bool Read( void* pbuffer, UINT size )=0;
      virtual bool Restart()=0;
      virtual UINT64 Seek(UINT64 offset, Direction direction = ISD_Forward )=0;
      virtual bool   SetOffset(UINT64 offset)=0;
      virtual UINT64 GetOffset()=0;
      virtual IFile* GetFile()=0;
      virtual Descriptions::Descriptor GetDescriptor()const=0;
    };
/*
    class Serializer
    {
    public:
      // std::sting
      inline static bool Serialize   (Serialization::IStream *pstream, string &str)
      {
        UINT64 size = str.size();
        pstream->Write( &size,   sizeof(UINT64) );
        pstream->Write( &str[0], str.size() );
        return true;
      }
      inline static bool Deserialize (Serialization::IStream *pstream, string &str)
      {
        UINT64 size = 0;
        pstream->Read( &size, sizeof(UINT64) );
        str.resize( size );
        if( 0 == size ) return true;
        pstream->Read( &str[0], str.size() );
        return true;        
      }
      // UINT64:
      inline static bool Serialize   (Serialization::IStream *pstream, UINT64 &value)
      {
        return pstream->Write( &value, sizeof(UINT64) );
      }
      inline static bool Deserialize (Serialization::IStream *pstream, UINT64 &value)
      {
        return pstream->Read( &value, sizeof(UINT64) );
      }
    };
*/
    class ISerializable
    {
    public:
      virtual bool Deserialize (Serialization::IStream *pstream)=0;
      virtual bool Serialize   (Serialization::IStream *pstream)=0;
    };
    /*
    class FileStream : public IStream, public IFile
    {
    private:
      IFile  *pFile;
      UINT64  Offset;
      UINT64  OffsetOrigin;
      Descriptions::Descriptor FileDescription;
    public:
      FileStream(IFile *pfile)
      {
        pFile  = pfile;
        Offset = 0;
        OffsetOrigin = 0;
        FileDescription = pfile->GetDescriptor();
      }
      FileStream(Serialization::IStream  *ptr)
      {
        pFile  = ptr->GetFile();
        Offset = 0;
        OffsetOrigin = ptr->GetOffset();
        FileDescription = ptr->GetDescriptor();
      };
      FileStream(const FileStream& ptr)
      {
        pFile  = ptr.pFile;
        Offset = 0;
        OffsetOrigin = ptr.Offset; 
        FileDescription = ptr.GetDescriptor();
      };
      virtual bool Write( void* pbuffer, UINT size )
      {
        if( pFile->Write(pbuffer, OffsetOrigin+Offset, size) )
        {
          Seek(size);
          return true;
        }
        else
        {
          return false;
        };
      }
      virtual bool Read( void* pbuffer, UINT size )
      {
        if( pFile->Read(pbuffer, OffsetOrigin+Offset, size) )
        {
          Seek(size);
          return true;
        }
        else
        {
          return false;
        };
      }
      virtual bool Restart()
      {
        Offset = OffsetOrigin;
        return true;
      }
      virtual UINT64 Seek(UINT64 offset, Direction direction = ISD_Forward )
      {
        if( ISD_Forward == direction )
          Offset += offset;
        else
          Offset -= offset;
        return true;
      }
      virtual bool   SetOffset(UINT64 offset)
      {
        Offset = offset;
        return true;
      }
      virtual UINT64 GetOffset()
      {
        return Offset;
      }
      virtual IFile* GetFile()
      {
        return pFile;
      }
      virtual bool Write( void* pbuffer, UINT offset, UINT size )
      {
        return pFile->Write(pbuffer,offset,size);
      }
      virtual bool Read ( void* pbuffer, UINT offset, UINT size )
      {
        return pFile->Read(pbuffer,offset,size);
      }
      virtual UINT64 GetSize()
      {
        return pFile->GetSize();
      }
      virtual Descriptions::Descriptor GetDescriptor()const
      {
        return FileDescription;
      }
    };
    //
    class USCFile : public IFile, public IStream
    {
    private:
      UINT64 Offset;
      Streaming::IFile *pfile;
      Descriptions::Descriptor FileDescription;
    public:
      USCFile(string name)
      {
        Offset = 0;
        pfile = Streaming::Singletone::GetInstance()->CreateFile(name);
        FileDescription.CreationState = pfile->IsCreated()?Descriptions::ISCS_Created:Descriptions::ISCS_Opened;
      }
      //
      virtual bool Write( void* pbuffer, UINT offset, UINT size )
       {
         return pfile->Write(offset,size,pbuffer,size);
       }
      virtual bool Read ( void* pbuffer, UINT offset, UINT size )
       {
         return pfile->Read(pbuffer,size,offset,size);
       }
      virtual UINT64 GetSize()
       {
         return pfile->GetSize();
       }
      virtual bool Write( void* pbuffer, UINT size )
      {
        if ( Write(pbuffer,Offset,size) )
        {
          Offset += size;
          return true;
        }
        else
        {
          Restart();
          return false;
        }
      };
      virtual bool Read( void* pbuffer, UINT size )
      {
        if ( Read(pbuffer,Offset,size) )
        {
          Offset += size;
          return true;
        }
        else
        {
          Restart();
          return false;
        }
      };
      virtual bool Restart()
      {
        Offset = 0;
        return true;
      }
      virtual UINT64 Seek(UINT64 offset, Direction direction = ISD_Forward )
      {
        if( ISD_Forward == direction )
          Offset += offset;
        else
          Offset -= offset;
        return true;
      }
      virtual bool SetOffset(UINT64 offset)
      {
        Offset = offset;
        return true;
      }
      virtual UINT64 GetOffset()
      {
        return Offset;
      }
      virtual IFile* GetFile()
      {
        return this;
      }
      //
      virtual Descriptions::Descriptor GetDescriptor()const
      {
        return FileDescription;
      }
    };
    //
    enum BufferingType
    {
      BT_Unknown,
      BT_Direct,
      BT_Static,
      BT_Cached,
    };
    //
    class StreamBuffered : public Serialization::IStream, public Controll::Controller //, public Serialization::ISerializable
    {
    private:
      class IStreamingTechnique : public Serialization::IStream, public Controll::IControllable
      {
      public:
        // IStreamingTechnique:
        /*
        virtual bool CreateObject ( Serialization::IStream *pstream  )=0; 
        virtual bool ParseObject  ( Serialization::IStream *pstream  )=0;
        virtual bool IsCreated ( )=0;    
        virtual bool IsParsed  ( )=0;
        *
        virtual UINT64 GetSize ( )const=0;
        virtual bool SetSize   ( UINT64 size )=0; 
        // Controller:
        virtual bool OnPrepare( )=0;
        virtual bool OnInstall( ) { return true; }
        virtual bool OnRelease( )=0;
        // IStream: 
        virtual bool   Write  ( void* pbuffer, UINT size )=0; 
        virtual bool   Read   ( void* pbuffer, UINT size )=0; 
        virtual bool   Restart( )=0; 
        virtual UINT64 Seek   ( UINT64 offset, Direction direction = ISD_Forward )=0; 
        virtual Serialization::IFile* GetFile( )=0;
        virtual bool   SetOffset( UINT64 offset )=0; 
        virtual UINT64 GetOffset( )=0;
        //
        virtual Descriptions::Descriptor GetDescriptor(void) const=0;
      };
      class DirectStream : public IStreamingTechnique //Need to save total size and data - directly in file! 
      { 
      private: 
        Serialization::FileStream *pStream; 
        UINT64 Size;
      private:
        UINT64 SizeOffset;
        UINT64 DataOffset;
        //Descriptions::CreationStates CreationState;
        Descriptions::Descriptor LocalDescriptor;
      public: 
        void CorrectSize(UINT64 size) 
        { 
          UINT64 NewSize = (pStream->GetOffset()-DataOffset)+size; // Is used because the Reset() command should handled correctly.
          if( NewSize > Size )
          {
            // So, the size is truly increased:
            Size += size;
            UINT64 CurrentOffset = pStream->GetOffset();        
            pStream->SetOffset(SizeOffset); 
            pStream->Write(&Size,sizeof(UINT64)); 
            pStream->SetOffset(CurrentOffset); 
          }
        } 
      public: 
        /*
        DirectStream( Serialization::IStream *pstream = NULL ) 
        { 
          pStream = pstream;
        }
        *
        DirectStream():pStream(NULL) { LocalDescriptor.CreationState = Descriptions::ISCS_Unknown; }
        // DirectStream:
        virtual bool CreateObject ( Serialization::IStream *pstream )
        {
          // Object is not created in Stream yet, we can use it only for consecutive information writing.
          Size     = 0;
          pStream  = new Serialization::FileStream(pstream); // We will use this stream to write data into it! 
          SizeOffset = pStream->GetOffset();
          if( pStream->Write( &Size, sizeof(UINT64) ) ) 
          { 
            // Get data offset to fill it`s data;
            DataOffset = pStream->GetOffset();
            LocalDescriptor.CreationState = Descriptions::ISCS_Created;
            return true;
          }
          else
          {
            pStream    = 0;            
            Size       = 0;
            SizeOffset = 0;
            DataOffset = 0;
            LocalDescriptor.CreationState = Descriptions::ISCS_Unknown;  
            return false;
          }
        }
        virtual bool ParseObject  ( Serialization::IStream *pstream )
        {
          // Object is already created in Stream, and wee can use it to parallel read and write information from|to it.
          pStream = new Serialization::FileStream( pstream ); // This is necessary to parallel resource preparation!
          SizeOffset = pStream->GetOffset();
          if( pStream->Read( &Size, sizeof(UINT64) ) ) 
          { 
            // The object is already created and it has size!
            DataOffset = pStream->GetOffset();
            pstream->Seek(sizeof(UINT64)+Size); // Shift original stream to next Object (Behind current Object) -
            LocalDescriptor.CreationState = Descriptions::ISCS_Opened;
            return true;             // to proper restoration of it;
          }
          else
          {
            // The resource parsing is failed! 
            delete pStream;
            pStream    = 0;
            Size       = 0;
            SizeOffset = 0;
            DataOffset = 0;
            LocalDescriptor.CreationState = Descriptions::ISCS_Unknown;            
            return false;
          }
        }
        virtual UINT64 GetSize() const
        { 
          return Size; 
        } 
        virtual bool SetSize   ( UINT64 size )
        {
          return Size = size;
        }
        // Controller:
        virtual bool OnPrepare()
        {
          return true; //Already prepared!
        }
        virtual bool OnRelease()
        {
          return true; //Already released!
        }      
        // IStream: 
        virtual bool   Write( void* pbuffer, UINT size ) 
        { 
          if( pStream->Write( pbuffer, size ) ) 
          { 
            if( Descriptions::ISCS_Created == LocalDescriptor.CreationState ) CorrectSize(size); 
            return true; 
          } 
          return false; 
        } 
        virtual bool   Read ( void* pbuffer, UINT size ) 
        { 
          // We reads data without Size;
          if( pStream->Read( pbuffer, size ) ) 
          { 
            return true;
          } 
          return false; 
        } 
        virtual bool   Restart( )
        { 
          return pStream->SetOffset( DataOffset ); 
        } 
        virtual UINT64 Seek( UINT64 offset, Direction direction = ISD_Forward ) 
        { 
          return pStream->Seek(offset,direction); 
        } 
        virtual bool   SetOffset( UINT64 offset ) 
        { 
          return pStream->SetOffset(offset); 
        } 
        virtual UINT64 GetOffset() 
        { 
          return pStream->GetOffset(); 
        } 
        virtual Serialization::IFile* GetFile() // Is it really necessarily? 
        { 
          return pStream->GetFile(); 
        } 
        //
        Descriptions::Descriptor GetDescriptor(void) const
        {
          if( Descriptions::ISCS_Unknown == LocalDescriptor.CreationState )
            return pStream->GetDescriptor();
          else
            return LocalDescriptor;
        } 
      }; 
      class StaticStream : public IStreamingTechnique
      { 
      protected: 
        vector<char> *pBuffer; 
        UINT64 Size; 
        UINT64 Offset; 
        DirectStream *pDirectStream;
        bool IsChanged;
      protected: 
        void StretchSize(UINT64 size) 
        { 
          Size += size; 
          if( pBuffer )
          {
            if( Size > pBuffer->size() ) pBuffer->resize(Size); 
          }
        } 
        void Resize(UINT64 size)
        { 
          Size = size; 
          if( pBuffer ) pBuffer->resize(Size);
        } 
      public: 
        StaticStream( DirectStream *pdirectstream, Collection::CacheCollection<vector<char>*> *pcache = NULL )
        {
          pDirectStream = pdirectstream;
          pBuffer = ( NULL == pcache ) ? new vector<char>() : 0; // If pcache==NULL then this is STATIC buffer (it should create it`s own static buffer and manage it)!
          Resize(0);
          Offset  = 0; 
        }
        /*
        StaticStream( UINT64 size, bool isStatic = true ) 
        { 
          pBuffer = ( true == isStatic ) ? new vector<char>() : 0 ; 
          Resize(size);
          Offset  = 0; 
        } 
        StaticStream( Serialization::IStream *pstream, bool isStatic = true ) 
        { 
          // We want to create resource in parallel thread on OnPrepare() event;
          // So, let`s prepare all necessary data for it!  
          pDirectStream = new DirectStream(/* pstream *);
          pBuffer = ( true == isStatic ) ? new vector<char>() : 0 ; 
          Resize( pDirectStream->GetSize() );
          Offset  = 0;
        } 
        */  
      // StaticStream:
        /*
        bool CreateObject ( Serialization::IStream *pstream  )  
        {
          pDirectStream = new DirectStream();
          pDirectStream->CreateObject( pstream );
          Size = 0;
          return true;
        }
        bool ParseObject  ( Serialization::IStream *pstream  )
        {
          pDirectStream = new DirectStream();
          if( pDirectStream->ParseObject( pstream ) )
          {
            Size = pDirectStream->GetSize();
            return true;
          }
          return false;
        }
        bool IsCreated()  { return pDirectStream->IsCreated(); }        
        bool IsParsed()   { return pDirectStream->IsParsed();  } 
        *
        UINT64 GetSize() const
        { 
          return Size; 
        } 
        bool SetSize( UINT64 size ) 
        { 
          Resize(size); 
          return true;
        }         
        // Controller:
        virtual bool OnPrepare() // Only if stream is specified !!!
        {
          if( pDirectStream )
          {
            // We should prepare it somehow:
            if( pBuffer )
            {
              return true;
            }
            else
            {
              // The buffer is readed only ones from stream!
              IsChanged = false;
              pBuffer = new vector<char>();
              pBuffer->resize(Size);
              pDirectStream->Restart();
              return pDirectStream->Read( &((*pBuffer)[0]), Size );
            }
          }
          return false;
        }
        virtual bool OnRelease()
        {
          if( pDirectStream && IsChanged )
          {
            // We should prepare it somehow:
            IsChanged = false;
            pDirectStream->Restart();
            return pDirectStream->Write( &((*pBuffer)[0]), Size );
          }
          return true; //Already released!
        }
        // IStream: 
        virtual bool   Write( void* pbuffer, UINT size ) 
        { 
          if( pBuffer ) 
          {  
            StretchSize(size); 
            memcpy(&((*pBuffer)[Offset]),pbuffer,size); 
            Seek(size); 
            IsChanged = true;
          }
          else
          {
            IsChanged = false;
          }
          return IsChanged; 
        } 
        virtual bool   Read ( void* pbuffer, UINT size ) 
        { 
          if( pBuffer ) 
          {  
            memcpy(pbuffer,&((*pBuffer)[Offset]),size); 
            Seek(size);
            return true; 
          }
          else
          {
            return false;
          }
        } 
        virtual bool   Restart() 
        { 
          Offset = 0;           
          return true;
        } 
        virtual UINT64 Seek(UINT64 offset, Direction direction = ISD_Forward ) 
        { 
          return Offset += offset; 
        } 
        virtual bool   SetOffset(UINT64 offset) 
        { 
          Offset = offset; 
          return true;
        } 
        virtual UINT64 GetOffset() 
        { 
          return Offset; 
        } 
        virtual Serialization::IFile* GetFile() // Is it really necessarily? 
        { 
          return NULL; 
        } 
        //
        virtual Descriptions::Descriptor GetDescriptor(void) const
        {
          return pDirectStream->GetDescriptor();
        }
      }; 
      class CachedStream : public StaticStream 
      { 
      protected: 
        Collection::CacheCollection<vector<char>*> *pCache;
        Collection::CacheCollection<vector<char>*>::ResourceContainer *pResourceContainer;
      protected: 
        inline bool GetResourceFromCache()
        {
          pBuffer = pResourceContainer->GetResource();
          if( pBuffer )
          {
            return true;
          }
          else
          {
            //Try to create it:
            vector<char> *pnewresource = new vector<char>();
            pnewresource->resize(Size);
            pBuffer = pResourceContainer->CreateAndGetResource(pnewresource);
            if( pBuffer )
            {
              return true;
            }
            else
            {
              return false;
            }
          }
        };    
        inline bool ReleaseResource()
        {
          if( pBuffer )
          {
            bool Result = true;
            if( IsChanged )
            {
              pDirectStream->Restart();
              Result = pDirectStream->Write( &((*pBuffer)[0]), Size );
            }
            pBuffer = 0;
            pResourceContainer->Release();
            return Result;
          }
          else
          {
            return true;
          }
        }
      public: 
        /*
        CachedStream( Serialization::IStream *pStream, Collection::CacheCollection<vector<char>*> *pcache ) : StaticStream( pStream, false )
        { 
          pCache = pcache;
          pResourceContainer = pCache->CreateResourceContainer();
        }       
        CachedStream( UINT64 size, Collection::CacheCollection<vector<char>*> *pcache ) : StaticStream( size, false )
        { 
          pCache = pcache;
          pResourceContainer = pCache->CreateResourceContainer();
        } 
        *
        CachedStream( DirectStream *pdirectstream, Collection::CacheCollection<vector<char>*> *pcache ):StaticStream( pdirectstream, pcache )
        {
          pCache = pcache;
          pResourceContainer = pCache->CreateResourceContainer();
        }
        // Controller:
        bool OnPrepare()
        {
          if( GetResourceFromCache() )
          {
            // We need to read data from stream int-to memory!
            if( pResourceContainer->IsUpdateNeeded() )
            {
              if( pDirectStream )
              {
                IsChanged = false;
                pBuffer->resize(Size);
                pDirectStream->Restart();
                return pDirectStream->Read( &((*pBuffer)[0]), Size );
              }
            }
          }
          return false;
        }
        bool OnRelease()
        {
          return ReleaseResource();
        }
      }; 
    private: 
      BufferingType BT;
      DirectStream *pDirectStream;
      IStreamingTechnique *pTechnique;
      Collection::CacheCollection<vector<char>*> *pCache;
      Serialization::IStream *pStream;
      Serialization::Descriptions::CreationStates CreationState;
    public: 
      StreamBuffered()
      {
        BT            = BT_Unknown;
        pDirectStream = NULL;
        pTechnique = NULL;
        pCache     = NULL;
        pStream    = NULL;
        CreationState = Serialization::Descriptions::ISCS_Unknown;
      }
      // StreamBuffered:
      bool SetBufferingType( BufferingType type, Collection::CacheCollection<vector<char>*> *pcache = NULL )
      {
        if( type == BT ) return true;
        BT = type;
        if( BT_Direct == type )
        {
          if( pTechnique && pDirectStream != pTechnique ) delete pTechnique;
          return pTechnique = pDirectStream;
        }
        else if( BT_Static == type )
        {
          if( pTechnique && pDirectStream != pTechnique ) delete pTechnique;
          return pTechnique = new StaticStream(pDirectStream);
        }
        else if( BT_Cached == type )
        {
          if( pcache ) pCache = pcache;
          if( pTechnique && pDirectStream != pTechnique ) delete pTechnique;
          return pTechnique = new CachedStream(pDirectStream,pCache);
        }
        else if( BT_Unknown == type )
        {
          if( pTechnique && pTechnique != pDirectStream ) delete pTechnique;
          return pTechnique = 0;
        }
      }
      BufferingType GetBufferingType()
      {
        return BT;
      }
      bool CreateObject ( Serialization::IStream *pstream  )  
      {
        if( NULL == pDirectStream ) // You have only one try per object to create;
        {
          pDirectStream = new DirectStream();
          pTechnique = pDirectStream;
          return pDirectStream->CreateObject(pstream);
        }
        return false;
      }
      bool ParseObject  ( Serialization::IStream *pstream  )
      {
        if( NULL == pDirectStream ) // You have only one try per object to parse;
        {
          pDirectStream = new DirectStream();
          pTechnique = pDirectStream;
          return pDirectStream->ParseObject(pstream);
        }
        return false;
      }
      /*
      bool IsCreated()  
      { 
        if( NULL == pDirectStream ) 
          return false;
        else
          return pDirectStream->IsCreated(); 
      }        
      bool IsParsed()   
      {
        if( NULL == pDirectStream ) 
          return false;
        else        
          return pDirectStream->IsParsed();  
      }       
      *
      UINT64 GetObjectSize() const
      { 
        return pTechnique->GetSize();
      }       
      // Controller:
      virtual bool OnPrepare()
      {
        return pTechnique->OnPrepare();
      }
      virtual bool OnInstall() { return true; }
      virtual bool OnRelease()
      {
        return pTechnique->OnPrepare();
      }
      // IStream:
      virtual bool   Write( void* pbuffer, UINT size ) 
      { 
        return pTechnique->Write(pbuffer,size);
      } 
      virtual bool   Read ( void* pbuffer, UINT size ) 
      { 
        return pTechnique->Read(pbuffer,size);
      } 
      virtual bool   Restart() 
      { 
        return pTechnique->Restart();
      } 
      virtual UINT64 Seek(UINT64 offset,Serialization::IStream::Direction direction) 
      { 
        return pTechnique->Seek(offset,direction);
      } 
      virtual bool   SetOffset(UINT64 offset) 
      { 
        return pTechnique->SetOffset(offset);
      } 
      virtual UINT64 GetOffset() 
      { 
        return pTechnique->GetOffset();
      } 
      virtual Serialization::IFile* GetFile()  // Is it really necessarily? 
      { 
        return pTechnique->GetFile(); 
      } 
      //
      virtual Descriptions::Descriptor GetDescriptor(void) const
      {
        return pTechnique->GetDescriptor();
      }
    }; 
    //
    class ObjectStream : public StreamBuffered//, public Serialization::ISerializable
    {
    private:
      struct ResourceDescriptor : Serialization::ISerializable
      {
        string Type;
        string Name;
        ResourceDescriptor()
        {
          Type = "";
          Name = "";
        }
        virtual bool Deserialize (Serialization::IStream *pstream)
        {
          Serialization::Serializer::Deserialize(pstream,Type);
          Serialization::Serializer::Deserialize(pstream,Name);
          return true;
        }
        virtual bool Serialize   (Serialization::IStream *pstream)
        {
          Serialization::Serializer::Serialize(pstream,Type);
          Serialization::Serializer::Serialize(pstream,Name);
          return true;
        }
      } Descriptor;
    public:
      ObjectStream() { } // Used with Parse Object;
      ObjectStream(string object_name, string object_type) // Used with Create Object;
      {
        Descriptor.Name = object_name;
        Descriptor.Type = object_type;
      }
      //
      string GetType()
      {
        return string(Descriptor.Type);
      }
      string GetName()
      {
        return string(Descriptor.Name);
      }
      // ObjectStream:       
      bool CreateObject ( Serialization::IStream *pstream  )  
      {
        //if( Descriptions::ISCS_Unknown == StreamBuffered::GetDescriptor().CreationState )
        {
          //pstream->Write(&Descriptor,sizeof(ResourceDescriptor));      
          Descriptor.Serialize(pstream);
          return StreamBuffered::CreateObject( pstream );
        }
        return false;
      }
      bool ParseObject  ( Serialization::IStream *pstream  )
      {
        //if( Descriptions::ISCS_Unknown == StreamBuffered::GetDescriptor().CreationState )
        {        
          //pstream->Read(&Descriptor,sizeof(ResourceDescriptor));
          Descriptor.Deserialize(pstream);
          return StreamBuffered::ParseObject( pstream );
        }
        return false;
      }
      //
    };
    */
  }

#endif /* ISERIALIZABLE */